<template>
  <div id="app">
    <router-view />
    <div v-show="isQiankun" id="microExchangePortalContainer" />
  </div>
</template>

<script>
import { getAccessToken } from '@/utils/auth'
import { getQiankunEnv, getCurrentMicroApp } from '@/utils/micro'

export default {
  name: 'App',
  data() {
    return {
      isQiankun: getQiankunEnv(),
      currentMicroApp: getCurrentMicroApp()
    }
  },
  metaInfo() {
    return {
      title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
      titleTemplate: (title) => {
        return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
      }
    }
  },
  created() {
    // const oldStore = window.sessionStorage.getItem('store')
    // // 第一次进入页面时为null，后面如果刷新页面将会有值，则会替换Vuex里面的数据
    // if (oldStore !== null) {
    //   this.$store.replaceState(
    //     Object.assign({}, this.$store.state, JSON.parse(oldStore))
    //   )
    // }
    // // 监听页面刷新，将store里面的数据保存到sessionStorage
    // window.addEventListener('beforeunload', () => {
    //   window.sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    // })
    const link = document.querySelector("link[rel*='icon']") || document.createElement('link')
    link.type = 'image/x-icon'
    link.rel = 'shortcut icon'
    link.href = this.$store.state.user.loginConfigData.browserUrl
    document.getElementsByTagName('head')[0].appendChild(link)
  },
  mounted() {
    const token = getAccessToken()
    if (token) {
      this.$websocket.initWebSocket(getAccessToken())
    }
  }
}
</script>
